package org.lord.slark.numbers.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import org.lord.slark.numbers.entity.ConferenceNumber;
import org.lord.slark.numbers.entity.MeetingNumber;
import org.lord.slark.numbers.entity.Saint;
import org.lord.slark.numbers.entity.Scripture;

public class LocalDBHelper extends SQLiteOpenHelper {
    public static final String DB_NAME = "saints_numbers.db";
    private static final String TAG = "LocalDBHelper";
    private static final int DB_VERSION = 1;

    public LocalDBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        createtable(db);
    }

    private void createtable(SQLiteDatabase db) {
        //TABLE Saint
        db.execSQL("CREATE TABLE " + Saint.TABLE_NAME + " ("
                + Saint.COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
                + Saint.COLUMN_GENDER + " INTEGER,"
                + Saint.COLUMN_NAME + " VARCHAR,"
                + Saint.COLUMN_PHONE + " VARCHAR,"
                + Saint.COLUMN_IS_BAPTIZED + " INTEGER"
                + ");");
        //TABLE ConferenceNumber
        db.execSQL("CREATE TABLE " + ConferenceNumber.TABLE_NAME + " ("
                + ConferenceNumber.COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
                + ConferenceNumber.COLUMN_TYPE + " VARCHAR,"
                + ConferenceNumber.COLUMN_TIME + " VARCHAR,"
                + ConferenceNumber.COLUMN_TOTAL + " INTEGER,"
                + ConferenceNumber.COLUMN_BRO_NUM + " INTEGER,"
                + ConferenceNumber.COLUMN_SIS_NUM + " INTEGER"
                + ");");
        //TABLE MeetingNumber
        db.execSQL("CREATE TABLE " + MeetingNumber.TABLE_NAME + " ("
                + MeetingNumber.COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
                + MeetingNumber.COLUMN_DATA + " VARCHAR,"
                + MeetingNumber.COLUMN_FREQUENCY + " INTEGER,"
                + MeetingNumber.COLUMN_START_TIME + " BIGINT,"
                + MeetingNumber.COLUMN_STATUS + " INTEGER,"
                + MeetingNumber.COLUMN_LAMBID + " INTEGER"
                + ");");
        //TABLE Scriptures
        db.execSQL("CREATE TABLE " + Scripture.TABLE_NAME + " ("
                + Scripture.COLUMN_ID + " INTEGER PRIMARY KEY,"
                + Scripture.COLUMN_ORIGIN + " VARCHAR,"
                + Scripture.COLUMN_CONTENT + " VARCHAR"
                + ");");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //used when we need upgrade the database.
    }
}
